<template>
  <section class="pageMain">
    <div class="detailsTop">
      <div class="left">
        <template v-if="productInfo.product_skus.length == 0">
          <img :src="productInfo.image" alt="">
          <div class="imgList">
            <img :src="productInfo.image" class="specSelectImg">
          </div>
        </template>
        <template v-else>
          <img :src=" $assetsURL + productInfo.product_skus[skuSelectIndex].spec_image" alt="">
          <div class="imgList">
            <img alt="" v-for="(item,index) in productInfo.product_skus" :src="$assetsURL + item.spec_image"
                 @click="specClick(index)" :class="skuSelectIndex == index? 'specSelectImg':''">
          </div>
        </template>
      </div>
      <div class="right">
        <div class="pClass">{{ productInfo.cname }}</div>
        <div class="pTitle">
          <span>{{ productInfo.title }}</span>
          <span class="part">{{ `${$t('productDetail.MLFB')}: ${productInfo.goods_no}` }}</span>
        </div>
        <div class="pDesc">{{ productInfo.desc }}
        </div>
        <div class="pPrice">
          <div>
            {{ $t('productDetail.price') }}
            <template v-if="productInfo.product_skus.length == 0">
              <span>￥{{ productInfo.price }}</span>
            </template>
            <template v-else>
              <span>￥{{ productInfo.product_skus[skuSelectIndex].spec_price }}</span>
            </template>
          </div>
        <div v-if="productInfo.product_skus.length == 0" style="color: #999999">
          {{ $t('productDetail.kuc') }}: {{ productInfo.stocks }}
        </div>

        </div>
        <hr/>
        <!--        参数-->
        <div class="parameter" v-if="productInfo.product_attr.length > 0">
          <div style="display: flex;justify-content: space-between">
            <div class="tips">{{ $t('productDetail.basic') }}</div>
            <el-popover
                placement="right"
                width="226"
                trigger="hover">
              <img :src="productInfo.qrcode_img" style="width: 200px;height: 200px">
              <div class="tip2" slot="reference">
                <img src="@/assets/icon/qrcode.png"
                     style="width: 16px;height: 16px;margin-right: 6px;margin-left: 10px;"
                     alt="">
                <span >二维码预览</span>
              </div>

            </el-popover>

          </div>

          <div class="parameterList">
            <div class="pl_item" v-for="(item,index) in productInfo.product_attr" :key="index">
              <div class="parameterList_item">
                <div class="pl_left">{{ item.name }}</div>
                <div class="pl_right">{{ item.value }}</div>
              </div>
            </div>

          </div>
        </div>
        <div class="spec" v-if="productInfo.product_skus.length > 0">
          <div class="tips">{{ $t('productDetail.selectModel') }}</div>
          <div class="tip2">{{ productInfo.product_skus[skuSelectIndex].spec_num }}<img src="@/assets/cx.png"
                                                                                        style="width: 16px;height: 16px;margin-right: 6px;margin-left: 10px;"
                                                                                        alt=""><span>{{
              $t('productDetail.query')
            }}</span>
          </div>
          <div class="specList">
            <div v-for="(item,index) in productInfo.product_skus" :class="skuSelectIndex == index? 'specSelect':''"
                 @click="specClick(index)">
              {{ item.spec_key }}
            </div>
          </div>
        </div>

        <el-button class="dBtn" @click="goBuy(productInfo.link)">{{ $t('productDetail.goBuy') }}</el-button>
      </div>
    </div>

    <div class="details">
      <el-tabs class="tabs" v-model="activeName">
        <el-tab-pane :label="$t('productDetail.p1')" name="first">
          <p v-html="productInfo.content"></p>
          <!--            <div class="param">-->
          <!--              <div class="paramItem">-->
          <!--                <div class="left">电气设计</div>-->
          <!--                <div class="right">PVP</div>-->
          <!--              </div>-->
          <!--              <div class="paramItem">-->
          <!--                <div class="left">电气设计</div>-->
          <!--                <div class="right">PVP</div>-->
          <!--              </div>-->
          <!--              <div class="paramItem">-->
          <!--                <div class="left">电气设计</div>-->
          <!--                <div class="right">PVP</div>-->
          <!--              </div>-->
          <!--            </div>-->
          <!--            <p class="paramDesc">适用于工业、移动、冷却和润滑应用 | 高防护等级，适应严苛工业环境的需求 | 工作温度范围广，因而能够灵活运用 | 由大感应范围和低传感器容差而来的安全检测 | 由于应用范围广而削减存储空-->
          <!--              间。适用于工业、移动、冷却和润滑应用 | 高防护等级，适应严苛工业环境的需求 | 工作温度范围广，因而能够灵活运用 | 由大感应范围和低传感器容差而来的安全检测 | 由于应用范围广而削减存-->
          <!--              储空间。</p>-->
        </el-tab-pane>
        <el-tab-pane :label="$t('productDetail.p2')" name="second">
          <div class="down">
            <div class="downRow title">
              <div>{{ $t('download.l1') }}</div>
              <div>{{ $t('download.l2') }}</div>
              <div>{{ $t('download.l3') }}</div>
              <div>{{ $t('download.l4') }}</div>
            </div>
            <div class="downRow item" v-for="item in productInfo.product_file">
              <div> {{ item.title }}</div>
              <div> {{ item.file_size }}kb</div>
              <div> {{ item.file_type }}</div>
              <div><a :href="$assetsURL + item.file_src"><img src="@/assets/down.png" alt=""
                                                              @click="downloadFile(item.file_src)"></a></div>
            </div>
          </div>
        </el-tab-pane>
      </el-tabs>
    </div>

  </section>

</template>

<script>
import {getProductDetail} from "@/api/product";

export default {
  name: "productDetails",
  data: () => ({
    activeName: 'first',
    productInfo: {},
    skuSelectIndex: 0
  }),
  created() {
    getProductDetail({id: this.$route.query.id}).then(res => {
      this.productInfo = res.data
    }).catch(err => {
      console.log(err)
    })
  },
  methods: {
    specClick(index) {
      this.skuSelectIndex = index
    },
    downloadFile() {

    },
    goBuy(link) {
      window.open(link, "_blank")
    }
  }
}
</script>

<style scoped lang="less">
.pageMain {
  .detailsTop {
    display: flex;
    width: 1200px;
    margin: 0 auto;
    padding-top: 50px;

    .left {
      width: 500px;

      img {
        width: 500px;
        height: 500px;
      }

      .specSelectImg {
        border: 1px solid #2359BF;
      }

      .imgList {
        width: 500px;
        height: 116px;
        display: flex;
        overflow-x: auto;
        overflow-y: hidden;
        //overflow: hidden;
        margin-top: 12px;

        img {
          display: inline-block;
          width: 116px;
          height: 116px;
          margin-right: 12px;
        }

        img:last-child {
          margin-right: 0;
        }
      }
    }

    .right {
      width: 650px;
      margin-left: 50px;

      .pClass {
        font-size: 22px;
        font-weight: 400;
        color: #333333;
      }

      .pTitle {
        font-size: 36px;
        font-weight: bold;
        color: #333333;
        margin-top: 10px;
        .part{
          font-size: 16px;
          color: #00A3E6;
          margin-left: 15px;
        }
      }

      .pDesc {
        color: #999999;
        font-size: 14px;
        line-height: 22px;
        margin-top: 10px;
        margin-bottom: 30px;
      }

      .pPrice {
        font-size: 14px;
        color: #333333;
        display: flex;
        justify-content: space-between;
        align-items: flex-end;
        span {
          font-weight: bold;
          color: #C40000;
          font-size: 32px;
        }
      }

      hr {
        margin: 20px 0 30px 0;
        background-color: #D8D8D8;
      }

      .spec {
        display: flex;
        justify-content: space-between;
        align-items: center;
        flex-wrap: wrap;

        .tips {
          font-size: 18px;
          color: #333333;
        }

        .tip2 {
          font-size: 16px;
          color: #666666;
          display: flex;
          align-items: center;
          cursor: pointer;

          span {
            color: #00A3E6;
          }
        }

        .specList {
          width: 100%;

          div {
            display: inline-block;
            box-sizing: inherit;
            width: 206px;
            height: 50px;
            margin-right: 16px;
            border: 1px solid #D8D8D8;
            margin-top: 16px;
            line-height: 50px;
            text-align: center;
            cursor: pointer;
          }

          div:nth-child(3n) {
            margin-right: 0;
          }

          .specSelect {
            border: 1px solid #00A3E6;
          }
        }
      }

      .parameter {
        font-size: 18px;
        color: #333333;

        .tips {
          font-size: 18px;
          color: #333333;
          margin-bottom: 10px;
        }
        .tip2 {
          font-size: 16px;
          color: #666666;
          cursor: pointer;
          display: flex;
          align-items: center;
          span {
            color: #00A3E6;
          }
        }

        .parameterList {

          .pl_item {
            display: inline-block;
            margin-right: calc((100% - 316px * 2));
            margin-top: 10px;

            .parameterList_item {
              display: flex;
              align-items: center;
              height: 40px;
              width: 316px;
              border: 1px solid #D8D8D8;
              color: #666666;
              font-size: 14px;


              .pl_left {
                width: 132px;
                height: 100%;
                line-height: 40px;
                background-color: #F6F6F6;
                text-align: center;
                border-right: 1px solid #D8D8D8;
              }

              .pl_right {
                width: 180px;
                box-sizing: border-box;
                padding: 0 18px;
                height: 100%;
                line-height: 40px;
              }
            }
          }

          .pl_item:nth-child(2n) {
            margin-right: 0;
          }

        }
      }

      .dBtn {
        margin-top: 50px;
        background-color: #00A3E6;
        width: 206px;
        height: 50px;
        color: #FFFFFF;
        font-size: 16px;
        //line-height: 50px;
      }
    }
  }

  .details {
    //margin-top: 60px;
    width: 1200px;
    margin: 60px auto;

    .tabs {
      /deep/ .el-tabs__header {
        .el-tabs__nav-wrap {
          .el-tabs__nav-scroll {
            .el-tabs__nav {
              .el-tabs__item {
                //color: #666666;
                font-size: 24px;
                padding: 0 20px !important;
              }
            }
          }
        }
      }
    }

    .param {
      width: 1200px;

      .paramItem:nth-child(2n) {
        margin-right: 0;
      }

      .paramItem {
        margin-top: 20px;
        width: 582px;
        height: 60px;
        display: inline-block;
        margin-right: 36px;
        font-size: 14px;
        line-height: 60px;

        .left {
          background-color: #F6F6F6;
          display: inline-block;
          border: 1px solid #D8D8D8;
          text-align: center;
          color: #666666;
          width: 130px;
          height: 100%;
          border-right: none;
        }

        .right {
          padding: 0 20px;
          height: 100%;
          display: inline-block;
          border: 1px solid #D8D8D8;
          width: 450px;
        }
      }
    }

    .paramDesc {
      margin-top: 30px;
      font-size: 14px;
      color: #666666;
    }

    .down {
      margin-top: 35px;
      width: 1200px;
      border: 1px solid #D8D8D8;

      .downRow {
        display: flex;
        width: 100%;

        div {
          width: 300px;
          padding: 12px 20px;

          img {
            width: 16px;
            height: 16px;
            cursor: pointer;
          }
        }

        div:nth-child(4) {
          text-align: right;
        }
      }

      .item {
        font-size: 14px;
        color: #00A3E6;
      }

      .title {
        color: #333333;
        font-weight: bold;
        font-size: 14px;
        background-color: #F6F6F6;
      }
    }
  }
}


</style>